import 'package:flutter/material.dart';

class ContentPager extends StatefulWidget {
ContentPager({Key key,
  @required this.onPageChangedCallbackfn,
  @required this.onContentPageController,
}):super(key:key);

  final Function onPageChangedCallbackfn;
  final ContentPageController onContentPageController;

  @override
  _ContentPagerState createState() => _ContentPagerState();
}

class _ContentPagerState extends State<ContentPager> {

  PageController _pageController = PageController();

  @override
  void initState() {
    _pageController = widget.onContentPageController._pageController;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: PageView(
            controller: _pageController,
            onPageChanged: (int index){
              widget.onPageChangedCallbackfn(index);
            },
            children: <Widget>[
              PageViewItem(color: Colors.red, index: 0),
              PageViewItem(color: Colors.green, index: 1),
              PageViewItem(color: Colors.yellow, index: 2),
              PageViewItem(color: Colors.pink, index: 3),
            ],
          ),
        )
      ],
    );
  }
}

class PageViewItem extends StatelessWidget {
  PageViewItem({Key key, this.color, this.index}) : super(key: key);
  final Color color;
  final int index;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(30),
      child: Container(
          color: color,
          child: Center(
            child: Text(
              'page $index',
              style: TextStyle(fontSize: 40),
            ),
          )),
    );
  }
}


class ContentPageController{
  PageController _pageController = PageController();

  void jumpToPage(int page){
    _pageController.jumpToPage(page);
  }
}